import {computed, ref, watch} from "vue"
import {useRoute} from "vue-router"
import tagsStore from "@/apps/admin/store/tags"

export function useTag() {
    const TStore = tagsStore()
    const Route = useRoute()
    const path = ref('')

    watch(() => Route, value => {
        if (Route?.meta?.auth !== null && Route?.meta?.show!==0) {
            TStore.addTags({
                path: Route.path,
                name: Route?.meta?.title,
                icon: Route?.meta?.icon
            })
        }
        path.value = Route.path
    }, {
        deep: true,
        immediate: true
    })


    /**
     * 设置标签页
     * @param tgs
     */
    function setTages(tgs: any[]) {
        TStore.setTags(tgs)
    }

    return {
        tags:computed(()=>TStore.tags),
        path,
        setTages
    }
}